package com.nifostasky.controller;


import com.nifostasky.entity.Student;
import com.nifostasky.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 学生信息表(Student)表控制层
 *
 * @author makejava
 * @since 2021-09-10 20:50:39
 */
@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    /**
     * 根据id查询学生信息
     */
    @GetMapping("/queryUserById/{id}")
    public Student queryUserById(@PathVariable("id")Integer id){
        System.out.println("========================调用8888服务提供者:queryUserById===============================");
        return studentService.queryUserById(id);
    }

    /**
     * 模拟超时熔断接口;
     * 这个服务至少得执行4000ms才能响应请求;
     */
    @GetMapping("/queryUserById4000ms/{id}")
    public Student queryUserById4000ms(@PathVariable("id")Integer id){
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("========================调用8888服务提供者:queryUserById4000ms===============================");
        return studentService.queryUserById(id);
    }

    /**
     * 生产者故意提供的错误,模拟异常熔断;
     */
    @GetMapping("/producerThrowable/{id}")
    public Student producerThrowable(@PathVariable("id")Integer id){
        //生产者故意提供的错误
        Integer age = 23/0;
        System.out.println("========================调用8888服务提供者:producerThrowable===============================");
        return studentService.queryUserById(id);
    }

}